using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Windows.Forms;

using PickGold.Charting.Utilities;
using PickGold.Charting.Design;

namespace PickGold.Charting
{
	[DefaultProperty("Name"), SRDescription("DescriptionAttributeLegendItem_LegendItem"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class LegendItem : ChartNamedElement, IChartMapArea
	{
		private string _attributes;
		private LegendCellCollection _cells;
		private System.Drawing.Color _color;
		private bool _enabled;
		private string _image;
		private int _markerBorderWidth;
		private string _postbackValue;
		private System.Drawing.Color _separatorColor;
		private LegendSeparatorStyle _separatorType;
		private string _seriesName;
		private int _seriesPointIndex;
		private string _toolTip;
		private string _url;
		internal GradientStyle backGradientStyle;
		internal ChartHatchStyle backHatchStyle;
		internal ChartImageAlignmentStyle backImageAlign;
		internal System.Drawing.Color backImageTransparentColor;
		internal ChartImageWrapMode backImageWrapMode;
		internal System.Drawing.Color backSecondaryColor;
		internal System.Drawing.Color borderColor;
		internal ChartDashStyle borderDashStyle;
		internal int borderWidth;
		internal bool clearTempCells;
		internal System.Drawing.Color markerBorderColor;
		internal System.Drawing.Color markerColor;
		internal string markerImage;
		internal System.Drawing.Color markerImageTransparentColor;
		internal int markerSize;
		internal MarkerStyle markerStyle;
		internal System.Drawing.Color shadowColor;
		internal int shadowOffset;
		internal LegendImageStyle style;

		public LegendItem()
		{
			this._color = System.Drawing.Color.Empty;
			this._image = "";
			this._seriesName = "";
			this._seriesPointIndex = -1;
			this._toolTip = "";
			this._url = "";
			this._attributes = "";
			this._postbackValue = string.Empty;
			this.backSecondaryColor = System.Drawing.Color.Empty;
			this.backImageTransparentColor = System.Drawing.Color.Empty;
			this.borderColor = System.Drawing.Color.Black;
			this.borderWidth = 1;
			this.borderDashStyle = ChartDashStyle.Solid;
			this.shadowColor = System.Drawing.Color.FromArgb(0x80, 0, 0, 0);
			this.markerSize = 5;
			this.markerImage = "";
			this.markerImageTransparentColor = System.Drawing.Color.Empty;
			this.markerColor = System.Drawing.Color.Empty;
			this.markerBorderColor = System.Drawing.Color.Empty;
			this._enabled = true;
			this._markerBorderWidth = 1;
			this._separatorColor = System.Drawing.Color.Black;
			this._cells = new LegendCellCollection(this);
			this.PostBackValue = string.Empty;
		}

		public LegendItem(string name, System.Drawing.Color color, string image)
			: base(name)
		{
			this._color = System.Drawing.Color.Empty;
			this._image = "";
			this._seriesName = "";
			this._seriesPointIndex = -1;
			this._toolTip = "";
			this._url = "";
			this._attributes = "";
			this._postbackValue = string.Empty;
			this.backSecondaryColor = System.Drawing.Color.Empty;
			this.backImageTransparentColor = System.Drawing.Color.Empty;
			this.borderColor = System.Drawing.Color.Black;
			this.borderWidth = 1;
			this.borderDashStyle = ChartDashStyle.Solid;
			this.shadowColor = System.Drawing.Color.FromArgb(0x80, 0, 0, 0);
			this.markerSize = 5;
			this.markerImage = "";
			this.markerImageTransparentColor = System.Drawing.Color.Empty;
			this.markerColor = System.Drawing.Color.Empty;
			this.markerBorderColor = System.Drawing.Color.Empty;
			this._enabled = true;
			this._markerBorderWidth = 1;
			this._separatorColor = System.Drawing.Color.Black;
			this._color = color;
			this._image = image;
			this._cells = new LegendCellCollection(this);
			this.PostBackValue = string.Empty;
		}

		internal void AddAutomaticCells(Legend legend)
		{
			if (this.Cells.Count == 0)
			{
				if (this.SeriesName.Length > 0)
				{
					if (legend.CellColumns.Count == 0)
					{
						if ((legend.Common != null) && (legend.Common.ChartPicture.RightToLeft == RightToLeft.Yes))
						{
							this.Cells.Add(LegendCellType.Text, "#LEGENDTEXT", ContentAlignment.MiddleLeft);
							this.Cells.Add(LegendCellType.SeriesSymbol, string.Empty, ContentAlignment.MiddleCenter);
						}
						else
						{
							this.Cells.Add(LegendCellType.SeriesSymbol, string.Empty, ContentAlignment.MiddleCenter);
							this.Cells.Add(LegendCellType.Text, "#LEGENDTEXT", ContentAlignment.MiddleLeft);
						}
					}
					else
					{
						foreach (LegendCellColumn column in legend.CellColumns)
						{
							this.Cells.Add(column.CreateNewCell());
						}
					}
				}
				else
				{
					this.clearTempCells = true;
					this.Cells.Add(LegendCellType.SeriesSymbol, string.Empty, ContentAlignment.MiddleCenter);
					this.Cells.Add(LegendCellType.Text, "#LEGENDTEXT", ContentAlignment.MiddleLeft);
				}
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && (this._cells != null))
			{
				this._cells.Dispose();
				this._cells = null;
			}
			base.Dispose(disposing);
		}

		private void Invalidate(bool invalidateLegendOnly)
		{
		}

		internal void SetAttributes(CommonElements common, Series series)
		{
			this.style = common.ChartTypeRegistry.GetChartType(series.ChartTypeName).GetLegendImageStyle(series);
			this._seriesName = series.Name;
			this.shadowOffset = series.ShadowOffset;
			this.shadowColor = series.ShadowColor;
			bool flag = common.Chart.ChartAreas[series.ChartArea].Area3DStyle.Enable3D;
			this.SetAttributes(series, flag);
		}

		internal void SetAttributes(DataPointCustomProperties properties, bool area3D)
		{
			this.borderColor = properties.BorderColor;
			this.borderWidth = properties.BorderWidth;
			this.borderDashStyle = properties.BorderDashStyle;
			this.markerStyle = properties.MarkerStyle;
			this.markerSize = properties.MarkerSize;
			this.markerImage = properties.MarkerImage;
			this.markerImageTransparentColor = properties.MarkerImageTransparentColor;
			this.markerColor = properties.MarkerColor;
			this.markerBorderColor = properties.MarkerBorderColor;
			this._markerBorderWidth = properties.MarkerBorderWidth;
			float dpiX = 96f;
			if (base.Common != null)
			{
				dpiX = base.Common.graph.Graphics.DpiX;
			}
			int num2 = (int)Math.Round((double)((2f * dpiX) / 96f));
			if (this._markerBorderWidth > num2)
			{
				this._markerBorderWidth = num2;
			}
			if (properties.MarkerBorderWidth <= 0)
			{
				this.markerBorderColor = System.Drawing.Color.Transparent;
			}
			if ((this.style == LegendImageStyle.Line) && (this.borderWidth <= ((int)Math.Round((double)(dpiX / 96f)))))
			{
				this.borderWidth = num2;
			}
			if (!area3D)
			{
				this.backGradientStyle = properties.BackGradientStyle;
				this.backSecondaryColor = properties.BackSecondaryColor;
				this.backImageTransparentColor = properties.BackImageTransparentColor;
				this.backImageWrapMode = properties.BackImageWrapMode;
				this.backImageAlign = properties.BackImageAlignment;
				this.backHatchStyle = properties.BackHatchStyle;
			}
		}

		[SRDescription("DescriptionAttributeBackGradientStyle"), Editor(typeof(GradientEditor), typeof(UITypeEditor)), Bindable(true), DefaultValue(0), SRCategory("CategoryAttributeAppearance"), PersistenceMode(PersistenceMode.Attribute)]
		public GradientStyle BackGradientStyle
		{
			get
			{
				return this.backGradientStyle;
			}
			set
			{
				this.backGradientStyle = value;
				this.Invalidate(true);
			}
		}

		[DefaultValue(0), SRCategory("CategoryAttributeAppearance"), Editor(typeof(HatchStyleEditor), typeof(UITypeEditor)), Bindable(true), SRDescription("DescriptionAttributeBackHatchStyle"), PersistenceMode(PersistenceMode.Attribute)]
		public ChartHatchStyle BackHatchStyle
		{
			get
			{
				return this.backHatchStyle;
			}
			set
			{
				this.backHatchStyle = value;
				this.Invalidate(true);
			}
		}

		[SRDescription("DescriptionAttributeImageTransparentColor"), NotifyParentProperty(true), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.Attribute), TypeConverter(typeof(ColorConverter)), SRCategory("CategoryAttributeAppearance"), Bindable(true), DefaultValue(typeof(System.Drawing.Color), "")]
		public System.Drawing.Color BackImageTransparentColor
		{
			get
			{
				return this.backImageTransparentColor;
			}
			set
			{
				this.backImageTransparentColor = value;
				this.Invalidate(true);
			}
		}

		[SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeBackSecondaryColor"), TypeConverter(typeof(ColorConverter)), PersistenceMode(PersistenceMode.Attribute), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), Bindable(true), DefaultValue(typeof(System.Drawing.Color), "")]
		public System.Drawing.Color BackSecondaryColor
		{
			get
			{
				return this.backSecondaryColor;
			}
			set
			{
				if ((value != System.Drawing.Color.Empty) && ((value.A != 0xff) || (value == System.Drawing.Color.Transparent)))
				{
					throw new ArgumentException(SR.ExceptionBackSecondaryColorIsTransparent);
				}
				this.backSecondaryColor = value;
				this.Invalidate(true);
			}
		}

		[DefaultValue(typeof(System.Drawing.Color), "Black"), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.Attribute), Bindable(true), SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeBorderColor")]
		public System.Drawing.Color BorderColor
		{
			get
			{
				return this.borderColor;
			}
			set
			{
				this.borderColor = value;
				this.Invalidate(true);
			}
		}

		[PersistenceMode(PersistenceMode.Attribute), SRDescription("DescriptionAttributeBorderDashStyle"), Bindable(true), SRCategory("CategoryAttributeAppearance"), DefaultValue(5)]
		public ChartDashStyle BorderDashStyle
		{
			get
			{
				return this.borderDashStyle;
			}
			set
			{
				this.borderDashStyle = value;
				this.Invalidate(true);
			}
		}

		[SRCategory("CategoryAttributeAppearance"), PersistenceMode(PersistenceMode.Attribute), Bindable(true), DefaultValue(1), SRDescription("DescriptionAttributeBorderWidth")]
		public int BorderWidth
		{
			get
			{
				return this.borderWidth;
			}
			set
			{
				if (value < 0)
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionBorderWidthIsZero);
				}
				this.borderWidth = value;
				this.Invalidate(false);
			}
		}

		[PersistenceMode(PersistenceMode.InnerProperty), SRDescription("DescriptionAttributeLegendItem_Cells"), SRCategory("CategoryAttributeAppearance"), Editor(typeof(LegendCellCollectionEditor), typeof(UITypeEditor))]
		public LegendCellCollection Cells
		{
			get
			{
				return this._cells;
			}
		}

		[TypeConverter(typeof(ColorConverter)), Bindable(true), DefaultValue(typeof(System.Drawing.Color), ""), NotifyParentProperty(true), SRCategory("CategoryAttributeAppearance"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.Attribute), SRDescription("DescriptionAttributeLegendItem_Color")]
		public System.Drawing.Color Color
		{
			get
			{
				return this._color;
			}
			set
			{
				this._color = value;
				this.Invalidate(true);
			}
		}

		[ParenthesizePropertyName(true), SRDescription("DescriptionAttributeLegendItem_Enabled"), SRCategory("CategoryAttributeAppearance"), DefaultValue(true)]
		public bool Enabled
		{
			get
			{
				return this._enabled;
			}
			set
			{
				this._enabled = value;
				this.Invalidate(false);
			}
		}

		[SRCategory("CategoryAttributeAppearance"), SRDescription("DescriptionAttributeLegendItem_Image"), DefaultValue(""), Editor(typeof(ImageValueEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.Attribute), NotifyParentProperty(true), Bindable(true)]
		public string Image
		{
			get
			{
				return this._image;
			}
			set
			{
				this._image = value;
				this.Invalidate(false);
			}
		}

		[PersistenceMode(PersistenceMode.Attribute), DefaultValue(typeof(LegendImageStyle), "Rectangle"), SRDescription("DescriptionAttributeLegendItem_Style"), SRCategory("CategoryAttributeAppearance"), ParenthesizePropertyName(true), Bindable(true)]
		public LegendImageStyle ImageStyle
		{
			get
			{
				return this.style;
			}
			set
			{
				this.style = value;
				this.Invalidate(true);
			}
		}

		[Bindable(false), SerializationVisibility(SerializationVisibility.Hidden), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public Legend Legend
		{
			get
			{
				if (this.Parent != null)
				{
					return (this.Parent.Parent as Legend);
				}
				return null;
			}
		}

		[SRCategory("CategoryAttributeMapArea"), PersistenceMode(PersistenceMode.Attribute), Bindable(true), SRDescription("DescriptionAttributeMapAreaAttributes"), DefaultValue("")]
		public string MapAreaAttributes
		{
			get
			{
				return this._attributes;
			}
			set
			{
				this._attributes = value;
			}
		}

		[Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), SRDescription("DescriptionAttributeMarkerBorderColor"), SRCategory("CategoryAttributeMarker"), PersistenceMode(PersistenceMode.Attribute), RefreshProperties(RefreshProperties.All), TypeConverter(typeof(ColorConverter)), Bindable(true), DefaultValue(typeof(System.Drawing.Color), "")]
		public System.Drawing.Color MarkerBorderColor
		{
			get
			{
				return this.markerBorderColor;
			}
			set
			{
				this.markerBorderColor = value;
				this.Invalidate(true);
			}
		}

		[PersistenceMode(PersistenceMode.Attribute), SRCategory("CategoryAttributeMarker"), DefaultValue(1), SRDescription("DescriptionAttributeMarkerBorderWidth")]
		public int MarkerBorderWidth
		{
			get
			{
				return this._markerBorderWidth;
			}
			set
			{
				if (value < 0)
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionLegendMarkerBorderWidthIsNegative);
				}
				this._markerBorderWidth = value;
				this.Invalidate(false);
			}
		}

		[TypeConverter(typeof(ColorConverter)), DefaultValue(typeof(System.Drawing.Color), ""), SRCategory("CategoryAttributeMarker"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.Attribute), RefreshProperties(RefreshProperties.All), Bindable(true), SRDescription("DescriptionAttributeLegendItem_MarkerColor")]
		public System.Drawing.Color MarkerColor
		{
			get
			{
				return this.markerColor;
			}
			set
			{
				this.markerColor = value;
				this.Invalidate(true);
			}
		}

		[RefreshProperties(RefreshProperties.All), SRCategory("CategoryAttributeMarker"), DefaultValue(""), SRDescription("DescriptionAttributeMarkerImage"), Editor(typeof(ImageValueEditor), typeof(UITypeEditor)), Bindable(true), PersistenceMode(PersistenceMode.Attribute)]
		public string MarkerImage
		{
			get
			{
				return this.markerImage;
			}
			set
			{
				this.markerImage = value;
				this.Invalidate(true);
			}
		}

		[Bindable(true), DefaultValue(typeof(System.Drawing.Color), ""), SRDescription("DescriptionAttributeImageTransparentColor"), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), PersistenceMode(PersistenceMode.Attribute), RefreshProperties(RefreshProperties.All), SRCategory("CategoryAttributeMarker")]
		public System.Drawing.Color MarkerImageTransparentColor
		{
			get
			{
				return this.markerImageTransparentColor;
			}
			set
			{
				this.markerImageTransparentColor = value;
				this.Invalidate(true);
			}
		}

		[RefreshProperties(RefreshProperties.All), SRCategory("CategoryAttributeMarker"), Bindable(true), DefaultValue(5), SRDescription("DescriptionAttributeLegendItem_MarkerSize"), PersistenceMode(PersistenceMode.Attribute)]
		public int MarkerSize
		{
			get
			{
				return this.markerSize;
			}
			set
			{
				this.markerSize = value;
				this.Invalidate(false);
			}
		}

		[SRCategory("CategoryAttributeMarker"), RefreshProperties(RefreshProperties.All), Bindable(true), DefaultValue(0), SRDescription("DescriptionAttributeLegendItem_MarkerStyle"), PersistenceMode(PersistenceMode.Attribute), Editor(typeof(MarkerStyleEditor), typeof(UITypeEditor))]
		public MarkerStyle MarkerStyle
		{
			get
			{
				return this.markerStyle;
			}
			set
			{
				this.markerStyle = value;
				this.Invalidate(true);
			}
		}

		[SRCategory("CategoryAttributeAppearance"), Bindable(true), NotifyParentProperty(true), PersistenceMode(PersistenceMode.Attribute), ParenthesizePropertyName(true), SRDescription("DescriptionAttributeLegendItem_Name")]
		public override string Name
		{
			get
			{
				return base.Name;
			}
			set
			{
				base.Name = value;
			}
		}

		[SRDescription("DescriptionAttributePostBackValue"), SRCategory("CategoryAttributeMapArea"), DefaultValue("")]
		public string PostBackValue
		{
			get
			{
				return this._postbackValue;
			}
			set
			{
				this._postbackValue = value;
			}
		}

		[TypeConverter(typeof(ColorConverter)), SRCategory("CategoryAttributeAppearance"), Editor(typeof(ChartColorEditor), typeof(UITypeEditor)), DefaultValue(typeof(System.Drawing.Color), "Black"), SRDescription("DescriptionAttributeLegendItem_SeparatorColor")]
		public System.Drawing.Color SeparatorColor
		{
			get
			{
				return this._separatorColor;
			}
			set
			{
				if (value != this._separatorColor)
				{
					this._separatorColor = value;
					this.Invalidate(false);
				}
			}
		}

		[SRDescription("DescriptionAttributeLegendItem_Separator"), SRCategory("CategoryAttributeAppearance"), DefaultValue(typeof(LegendSeparatorStyle), "None")]
		public LegendSeparatorStyle SeparatorType
		{
			get
			{
				return this._separatorType;
			}
			set
			{
				if (value != this._separatorType)
				{
					this._separatorType = value;
					this.Invalidate(false);
				}
			}
		}

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(""), Browsable(false), SerializationVisibility(SerializationVisibility.Hidden), SRDescription("DescriptionAttributeLegendItem_SeriesName")]
		public string SeriesName
		{
			get
			{
				return this._seriesName;
			}
			set
			{
				this._seriesName = value;
			}
		}

		[SRDescription("DescriptionAttributeLegendItem_SeriesPointIndex"), DefaultValue(-1), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), SerializationVisibility(SerializationVisibility.Hidden), Browsable(false)]
		public int SeriesPointIndex
		{
			get
			{
				return this._seriesPointIndex;
			}
			set
			{
				this._seriesPointIndex = value;
			}
		}

		[PersistenceMode(PersistenceMode.Attribute), SRCategory("CategoryAttributeAppearance"), Bindable(true), DefaultValue(typeof(System.Drawing.Color), "128,0,0,0"), SRDescription("DescriptionAttributeShadowColor"), TypeConverter(typeof(ColorConverter)), Editor(typeof(ChartColorEditor), typeof(UITypeEditor))]
		public System.Drawing.Color ShadowColor
		{
			get
			{
				return this.shadowColor;
			}
			set
			{
				this.shadowColor = value;
				this.Invalidate(true);
			}
		}

		[DefaultValue(0), PersistenceMode(PersistenceMode.InnerProperty), SRCategory("CategoryAttributeAppearance"), Bindable(true), SRDescription("DescriptionAttributeShadowOffset")]
		public int ShadowOffset
		{
			get
			{
				return this.shadowOffset;
			}
			set
			{
				this.shadowOffset = value;
				this.Invalidate(false);
			}
		}

		[SRDescription("DescriptionAttributeToolTip"), SRCategory("CategoryAttributeMapArea"), DefaultValue(""), PersistenceMode(PersistenceMode.Attribute), Bindable(true)]
		public string ToolTip
		{
			get
			{
				return this._toolTip;
			}
			set
			{
				this._toolTip = value;
			}
		}

		[DefaultValue(""), PersistenceMode(PersistenceMode.Attribute), Editor(typeof(UrlValueEditor), typeof(UITypeEditor)), Bindable(true), SRDescription("DescriptionAttributeUrl"), SRCategory("CategoryAttributeMapArea")]
		public string Url
		{
			get
			{
				return this._url;
			}
			set
			{
				this._url = value;
			}
		}
	}
}

